package com.xueyi.aixihu.response.base;

import com.xueyi.aixihu.status.SystemCode;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 描述 基本响应类
 *
 * @auther 俞烨
 * @date 2022-08-13 09
 */
@Data
@NoArgsConstructor
public class BaseResponse<T> {


    private int code;
    private String msg;
    private T result;

    /**
     * 成功的构建
     *
     * @param result
     * @param <T>
     * @return
     */
    public static <T> BaseResponse<T> success(T result) {

        BaseResponse<T> baseResponse = new BaseResponse<T>();
        baseResponse.setCode(SystemCode.SUCCESS);
        baseResponse.setMsg("ok");
        baseResponse.setResult(result);
        return baseResponse;
    }


    /**
     * 自定义构建响应
     *
     * @param result
     * @param <T>
     * @return
     */
    public static <T> BaseResponse<T> build(int code, String msg, T result) {

        BaseResponse<T> baseResponse = new BaseResponse<T>();
        baseResponse.setCode(code);
        baseResponse.setMsg(msg);
        baseResponse.setResult(result);
        return baseResponse;
    }


    public BaseResponse(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
}
